package com.financing.wap.service.impl;

import java.util.Collections;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
 
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.financing.wap.common.Pager;
import com.financing.wap.dao.IProjectCommentsDao;
import com.financing.wap.dto.ProjectCommentsDTO;
import com.financing.wap.dto.ProjectCommentsLinkDTO;
import com.financing.wap.service.IProjectCommentsService;

@Service("projectCommentsService")
public class ProjectCommentsServiceImpl implements IProjectCommentsService{

	@Autowired
	private IProjectCommentsDao projectCommentsDao;

	@SuppressWarnings("unchecked")
	@Override
	public List<ProjectCommentsDTO> getCommentsList(ProjectCommentsDTO dto, Pager pager) {
		int count = projectCommentsDao.countCommentsList(dto);
		List<ProjectCommentsDTO> list;
		pager.setTotalCount(count);
		if(count <=0){
			list = Collections.EMPTY_LIST;
		}else{
			list = projectCommentsDao.getCommentsList(dto,pager);
		}
		return list;
	}

	@Override
	public ProjectCommentsDTO getComments(Integer id) {
		return projectCommentsDao.getComments(id);
	}

	@Override
	public int addComments(ProjectCommentsDTO comment) {
		return projectCommentsDao.addComments(comment);
	}

	@Override
	@Transactional(rollbackFor={Exception.class,RuntimeException.class})
	public boolean upComments(ProjectCommentsLinkDTO link) throws Exception {
		projectCommentsDao.addCommentsLink(link);
		projectCommentsDao.updateCommentsUpcount(link.getpCommentsId());
		return true;
	}

	@Override
	public ProjectCommentsLinkDTO queryCommentsLink(ProjectCommentsLinkDTO link) {
		return projectCommentsDao.queryCommentsLink(link);
	}

}
